//
//  LGHisReportTableHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/9/29.
//

#import "LGHisReportTableHeader.h"

@interface LGHisReportTableHeader()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
//@property (nonatomic , assign)CGFloat itemW;
/**   */
@property (nonatomic , strong)NSMutableArray *labelArray;

@end

@implementation LGHisReportTableHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
//        self.itemW = (Screen_W-viewPix(48))/4.0;
        self.clipsToBounds = YES;
        self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        [self addSubview:self.baseView];
        [self.baseView addSubview:self.titleBtn];
        
    }
    return self;
}

-(void)setItemArray:(NSArray *)itemArray{
    _itemArray = itemArray;
    NSInteger count = 0;
    for (NSDictionary *tempDic in itemArray) {
        NSString *content = LGNSString(tempDic[@"name"]);
        if (content.length == 0) {
            count++;
        }
    }
    CGFloat itemW = (Screen_W-viewPix(48)-viewPix(45)*count)/(itemArray.count-count);
    CGFloat left = viewPix(16);
    for (NSInteger i=0; i<itemArray.count; i++) {
        NSString *content = LGNSString(itemArray[i][@"name"]);
        CGFloat labelW = (content.length>0)?itemW:viewPix(45);
        UILabel *label = [UILabel lableWithText:content colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
        label.frame = CGRectMake(left, viewPix(59), labelW-viewPix(5), viewPix(20));
        [self.baseView addSubview:label];
        left += labelW;
    }
}

-(void)setTitle:(NSString *)title{
    _title = title;
    [self.titleBtn setTitle:title forState:UIControlStateNormal];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.frame = CGRectMake(viewPix(16), viewPix(8), Screen_W-viewPix(32), viewPix(150));
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#1F6CC6" imageName:@""];
        _titleBtn.frame = CGRectMake(0, viewPix(20), 112, 27);
        [_titleBtn setBackgroundImage:[UIImage imageNamed:@"就诊检查-蓝色"] forState:UIControlStateNormal];
    }
    return _titleBtn;
}

-(NSMutableArray *)labelArray{
    if(!_labelArray){
        _labelArray = [NSMutableArray array];
    }
    return _labelArray;
}

@end
